<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">客户管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>积分记录</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片 -->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <el-col :span="7">
          <el-input placeholder="请输入操作人员" v-model="query">
            <el-button slot="append" @click="serch" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <!--          <el-button type="primary" icon="el-icon-plus" circle @click="addLevel" ></el-button>-->
          <el-button type="info" icon="el-icon-refresh" circle @click="refresh"></el-button>
        </el-col>
      </el-row>

      <!-- 数据表格 -->
      <el-table :key="Math.random()"
                :data="tableData"
                border
                style="width: 100%" >
        <el-table-column
            fixed
            align="center"
            prop="id"
            label="Id"
        >
        </el-table-column>
        <el-table-column
            fixed
            align="center"
            prop="memberId"
            label="会员Id"
        >
        </el-table-column>
        <el-table-column
            align="center"
            prop="operateMan"
            label="操作人员"
        >
        </el-table-column>
        <el-table-column
            align="center"
            prop="operateNote"
            label="消费积分"
        >
        </el-table-column>
        <el-table-column
            align="center"
            prop="changeCount"
            label="总数"
        >
        </el-table-column>
        <el-table-column
            align="center"
            prop="changeType"
            label="积分变换类型"
        >
          <template slot-scope="scope">
            <p v-if="scope.row.changeType==1" >加积分</p>
            <p v-else>减积分</p>
          </template>
        </el-table-column>
        <el-table-column
            align="center"
            prop="sourceType"
            label="积分来源"
        >
          <template slot-scope="scope">
            <p v-if="scope.row.sourceType==1" >参与官方活动</p>
            <p v-else>自驾服务消费金额</p>
          </template>
        </el-table-column>
        <el-table-column
            align="center"
            prop="createTime"
            label="时间"
        >
        </el-table-column>
        <el-table-column
            align="center"
            fixed="right"
            label="操作"
            width="160">
          <template slot-scope="scope">
            <el-button type="danger" icon="el-icon-delete"  size="medium" circle @click="deleteClientLevel(scope.row.id)"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>


    </el-card>
  </div>
</template>

<script>
export default {
  name: "level",
  data() {
    return {
      //查询条件
      query:"",
      //当前页码
      currentPage: 1,
      //每页显示记录
      pageSize:5,
      //总条数
      total:0,
      //当前的记录数据
      tableData: [],
    }
  },
  created() {
    //页面加载自动执行
    this.ininIntegrationTable(this.currentPage,this.pageSize);
  },
  methods: {
    //给表单赋值，显示数据
    ininIntegrationTable(currentPage,pageSize){
      var that=this;
      this.$http.post(`/customer/integrationHistory/findIntegrationByPage/${currentPage}/${pageSize}?query=${this.query}`).then(function (resp) {
        if (resp.data.code===200){
          that.tableData=resp.data.data.records;
          that.total=resp.data.data.total;
        }else {
          that.$message.error(resp.data.msg);
        }
      })
    },
    //修改每页几条的方法
    handleSizeChange(val) {
      this.pageSize=val;
      this.ininIntegrationTable(this.currentPage,this.pageSize);
    },
    //修改页数的方法
    handleCurrentChange(val) {
      this.currentPage=val;
      this.ininIntegrationTable(this.currentPage,this.pageSize);
    },
    //模糊查询按钮的方法
    serch(){
      this.currentPage=1,
      this.pageSize=5,
      this.ininIntegrationTable(this.currentPage,this.pageSize);
    },
    //刷新局部页面
    refresh (){
      this.query='';
      this.ininIntegrationTable(1,this.pageSize);
    },

    //删除会员管理
    deleteClientLevel(id){
      var that=this;
      this.$confirm('确定删除吗？, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.delete(`/customer/integrationHistory/deleteIntegrationHistory/${id}`).then(function (resp) {
          if (resp.data.code!=200){
            return that.$message.error("删除失败");
          }else {
            if (that.total%that.pageSize==1){
              that.currentPage--;
            }else {
              that.currentPage = that.currentPage;
            }
            that.$message.success("删除成功");
            that.ininIntegrationTable(that.currentPage,that.pageSize);
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
  },
}
</script>

<style scoped>

</style>